<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Algorithms for Inference &#8212; pgmpy 0.1.2 documentation</title>
    
    <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '0.1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Reading and Writing from files" href="readwrite.html" />
    <link rel="prev" title="Sampling Methods" href="sampling.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="readwrite.html" title="Reading and Writing from files"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="sampling.html" title="Sampling Methods"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">pgmpy 0.1.2 documentation</a> &#187;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="index.html">
              <img class="logo" src="_static/logo.png" alt="Logo"/>
            </a></p>
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Algorithms for Inference</a><ul>
<li><a class="reference internal" href="#variable-elimination">Variable Elimination</a></li>
<li><a class="reference internal" href="#belief-propagation">Belief Propagation</a></li>
<li><a class="reference internal" href="#module-pgmpy.inference.mplp">MPLP</a></li>
<li><a class="reference internal" href="#module-pgmpy.inference.dbn_inference">Dynamic Bayesian Network Inference</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-pgmpy.inference.EliminationOrder">Elimination Ordering</a></li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="sampling.html"
                        title="previous chapter">Sampling Methods</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="readwrite.html"
                        title="next chapter">Reading and Writing from files</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/inference.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="algorithms-for-inference">
<h1>Algorithms for Inference<a class="headerlink" href="#algorithms-for-inference" title="Permalink to this headline">¶</a></h1>
<div class="section" id="variable-elimination">
<h2>Variable Elimination<a class="headerlink" href="#variable-elimination" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pgmpy.inference.ExactInference.VariableElimination">
<em class="property">class </em><code class="descclassname">pgmpy.inference.ExactInference.</code><code class="descname">VariableElimination</code><span class="sig-paren">(</span><em>model</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/ExactInference.html#VariableElimination"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.ExactInference.VariableElimination" title="Permalink to this definition">¶</a></dt>
<dd><dl class="method">
<dt id="pgmpy.inference.ExactInference.VariableElimination.induced_graph">
<code class="descname">induced_graph</code><span class="sig-paren">(</span><em>elimination_order</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/ExactInference.html#VariableElimination.induced_graph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.ExactInference.VariableElimination.induced_graph" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the induced graph formed by running Variable Elimination on the network.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>elimination_order: list, array like</strong></p>
<blockquote class="last">
<div><p>List of variables in the order in which they are to be eliminated.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.inference</span> <span class="k">import</span> <span class="n">VariableElimination</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">values</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">low</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">high</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">5</span><span class="p">)),</span>
<span class="gp">... </span>                      <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">inference</span> <span class="o">=</span> <span class="n">VariableElimination</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">inference</span><span class="o">.</span><span class="n">induced_graph</span><span class="p">([</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">])</span>
<span class="go">&lt;networkx.classes.graph.Graph at 0x7f34ac8c5160&gt;</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.inference.ExactInference.VariableElimination.induced_width">
<code class="descname">induced_width</code><span class="sig-paren">(</span><em>elimination_order</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/ExactInference.html#VariableElimination.induced_width"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.ExactInference.VariableElimination.induced_width" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the width (integer) of the induced graph formed by running Variable Elimination on the network.
The width is the defined as the number of nodes in the largest clique in the graph minus 1.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>elimination_order: list, array like</strong></p>
<blockquote class="last">
<div><p>List of variables in the order in which they are to be eliminated.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.inference</span> <span class="k">import</span> <span class="n">VariableElimination</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">values</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">low</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">high</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">5</span><span class="p">)),</span>
<span class="gp">... </span>                      <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">inference</span> <span class="o">=</span> <span class="n">VariableElimination</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">inference</span><span class="o">.</span><span class="n">induced_width</span><span class="p">([</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">])</span>
<span class="go">3</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.inference.ExactInference.VariableElimination.map_query">
<code class="descname">map_query</code><span class="sig-paren">(</span><em>variables=None</em>, <em>evidence=None</em>, <em>elimination_order=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/ExactInference.html#VariableElimination.map_query"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.ExactInference.VariableElimination.map_query" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the MAP Query over the variables given the evidence.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>variables: list</strong></p>
<blockquote>
<div><p>list of variables over which we want to compute the max-marginal.</p>
</div></blockquote>
<p><strong>evidence: dict</strong></p>
<blockquote>
<div><p>a dict key, value pair as {var: state_of_var_observed}
None if no evidence</p>
</div></blockquote>
<p><strong>elimination_order: list</strong></p>
<blockquote class="last">
<div><p>order of variable eliminations (if nothing is provided) order is
computed automatically</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.inference</span> <span class="k">import</span> <span class="n">VariableElimination</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">values</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">low</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">high</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">5</span><span class="p">)),</span>
<span class="gp">... </span>                      <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">inference</span> <span class="o">=</span> <span class="n">VariableElimination</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi_query</span> <span class="o">=</span> <span class="n">inference</span><span class="o">.</span><span class="n">map_query</span><span class="p">([</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">])</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.inference.ExactInference.VariableElimination.max_marginal">
<code class="descname">max_marginal</code><span class="sig-paren">(</span><em>variables=None</em>, <em>evidence=None</em>, <em>elimination_order=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/ExactInference.html#VariableElimination.max_marginal"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.ExactInference.VariableElimination.max_marginal" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the max-marginal over the variables given the evidence.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>variables: list</strong></p>
<blockquote>
<div><p>list of variables over which we want to compute the max-marginal.</p>
</div></blockquote>
<p><strong>evidence: dict</strong></p>
<blockquote>
<div><p>a dict key, value pair as {var: state_of_var_observed}
None if no evidence</p>
</div></blockquote>
<p><strong>elimination_order: list</strong></p>
<blockquote class="last">
<div><p>order of variable eliminations (if nothing is provided) order is
computed automatically</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.inference</span> <span class="k">import</span> <span class="n">VariableElimination</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">values</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">low</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">high</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">5</span><span class="p">)),</span>
<span class="gp">... </span>                      <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">inference</span> <span class="o">=</span> <span class="n">VariableElimination</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi_query</span> <span class="o">=</span> <span class="n">inference</span><span class="o">.</span><span class="n">max_marginal</span><span class="p">([</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">])</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.inference.ExactInference.VariableElimination.query">
<code class="descname">query</code><span class="sig-paren">(</span><em>variables</em>, <em>evidence=None</em>, <em>elimination_order=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/ExactInference.html#VariableElimination.query"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.ExactInference.VariableElimination.query" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>variables: list</strong></p>
<blockquote>
<div><p>list of variables for which you want to compute the probability</p>
</div></blockquote>
<p><strong>evidence: dict</strong></p>
<blockquote>
<div><p>a dict key, value pair as {var: state_of_var_observed}
None if no evidence</p>
</div></blockquote>
<p><strong>elimination_order: list</strong></p>
<blockquote class="last">
<div><p>order of variable eliminations (if nothing is provided) order is
computed automatically</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.inference</span> <span class="k">import</span> <span class="n">VariableElimination</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">values</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">low</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">high</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">5</span><span class="p">)),</span>
<span class="gp">... </span>                      <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">inference</span> <span class="o">=</span> <span class="n">VariableElimination</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi_query</span> <span class="o">=</span> <span class="n">inference</span><span class="o">.</span><span class="n">query</span><span class="p">([</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">])</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="belief-propagation">
<h2>Belief Propagation<a class="headerlink" href="#belief-propagation" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pgmpy.inference.ExactInference.BeliefPropagation">
<em class="property">class </em><code class="descclassname">pgmpy.inference.ExactInference.</code><code class="descname">BeliefPropagation</code><span class="sig-paren">(</span><em>model</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/ExactInference.html#BeliefPropagation"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.ExactInference.BeliefPropagation" title="Permalink to this definition">¶</a></dt>
<dd><p>Class for performing inference using Belief Propagation method.</p>
<p>Creates a Junction Tree or Clique Tree (JunctionTree class) for the input
probabilistic graphical model and performs calibration of the junction tree
so formed using belief propagation.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>model: BayesianModel, MarkovModel, FactorGraph, JunctionTree</strong></p>
<blockquote class="last">
<div><p>model for which inference is to performed</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="pgmpy.inference.ExactInference.BeliefPropagation.calibrate">
<code class="descname">calibrate</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/ExactInference.html#BeliefPropagation.calibrate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.ExactInference.BeliefPropagation.calibrate" title="Permalink to this definition">¶</a></dt>
<dd><p>Calibration using belief propagation in junction tree or clique tree.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">TabularCPD</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.inference</span> <span class="k">import</span> <span class="n">BeliefPropagation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">),</span>
<span class="gp">... </span>                   <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;SAT&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;grade&#39;</span><span class="p">,</span> <span class="s1">&#39;letter&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diff_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.2</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.8</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">intel_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.5</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.3</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.2</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">grade_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;grade&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span>
<span class="gp">... </span>                       <span class="p">[[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">],</span>
<span class="gp">... </span>                        <span class="p">[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">],</span>
<span class="gp">... </span>                        <span class="p">[</span><span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">]],</span>
<span class="gp">... </span>                       <span class="n">evidence</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;intel&#39;</span><span class="p">],</span>
<span class="gp">... </span>                       <span class="n">evidence_card</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sat_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;SAT&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span>
<span class="gp">... </span>                     <span class="p">[[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">],</span>
<span class="gp">... </span>                      <span class="p">[</span><span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">]],</span>
<span class="gp">... </span>                     <span class="n">evidence</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;intel&#39;</span><span class="p">],</span> <span class="n">evidence_card</span><span class="o">=</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">letter_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;letter&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span>
<span class="gp">... </span>                        <span class="p">[[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">],</span>
<span class="gp">... </span>                         <span class="p">[</span><span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">]],</span>
<span class="gp">... </span>                        <span class="n">evidence</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;grade&#39;</span><span class="p">],</span> <span class="n">evidence_card</span><span class="o">=</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_cpds</span><span class="p">(</span><span class="n">diff_cpd</span><span class="p">,</span> <span class="n">intel_cpd</span><span class="p">,</span> <span class="n">grade_cpd</span><span class="p">,</span> <span class="n">sat_cpd</span><span class="p">,</span> <span class="n">letter_cpd</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bp</span> <span class="o">=</span> <span class="n">BeliefPropagation</span><span class="p">(</span><span class="n">G</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bp</span><span class="o">.</span><span class="n">calibrate</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.inference.ExactInference.BeliefPropagation.get_clique_beliefs">
<code class="descname">get_clique_beliefs</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/ExactInference.html#BeliefPropagation.get_clique_beliefs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.ExactInference.BeliefPropagation.get_clique_beliefs" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns clique beliefs. Should be called after the clique tree (or
junction tree) is calibrated.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.inference.ExactInference.BeliefPropagation.get_cliques">
<code class="descname">get_cliques</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/ExactInference.html#BeliefPropagation.get_cliques"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.ExactInference.BeliefPropagation.get_cliques" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns cliques used for belief propagation.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.inference.ExactInference.BeliefPropagation.get_sepset_beliefs">
<code class="descname">get_sepset_beliefs</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/ExactInference.html#BeliefPropagation.get_sepset_beliefs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.ExactInference.BeliefPropagation.get_sepset_beliefs" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns sepset beliefs. Should be called after clique tree (or junction
tree) is calibrated.</p>
</dd></dl>

<dl class="method">
<dt id="pgmpy.inference.ExactInference.BeliefPropagation.map_query">
<code class="descname">map_query</code><span class="sig-paren">(</span><em>variables=None</em>, <em>evidence=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/ExactInference.html#BeliefPropagation.map_query"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.ExactInference.BeliefPropagation.map_query" title="Permalink to this definition">¶</a></dt>
<dd><p>MAP Query method using belief propagation.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>variables: list</strong></p>
<blockquote>
<div><p>list of variables for which you want to compute the probability</p>
</div></blockquote>
<p><strong>evidence: dict</strong></p>
<blockquote class="last">
<div><p>a dict key, value pair as {var: state_of_var_observed}
None if no evidence</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">TabularCPD</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.inference</span> <span class="k">import</span> <span class="n">BeliefPropagation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bayesian_model</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;J&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;R&#39;</span><span class="p">,</span> <span class="s1">&#39;J&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;J&#39;</span><span class="p">,</span> <span class="s1">&#39;Q&#39;</span><span class="p">),</span>
<span class="gp">... </span>                                <span class="p">(</span><span class="s1">&#39;J&#39;</span><span class="p">,</span> <span class="s1">&#39;L&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="s1">&#39;L&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_a</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.2</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.8</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_r</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;R&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.4</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.6</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_j</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;J&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span>
<span class="gp">... </span>                   <span class="p">[[</span><span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">],</span>
<span class="gp">... </span>                    <span class="p">[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">]],</span>
<span class="gp">... </span>                   <span class="p">[</span><span class="s1">&#39;R&#39;</span><span class="p">,</span> <span class="s1">&#39;A&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_q</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;Q&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span>
<span class="gp">... </span>                   <span class="p">[[</span><span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">],</span>
<span class="gp">... </span>                    <span class="p">[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">]],</span>
<span class="gp">... </span>                   <span class="p">[</span><span class="s1">&#39;J&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_l</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;L&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span>
<span class="gp">... </span>                   <span class="p">[[</span><span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.45</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">],</span>
<span class="gp">... </span>                    <span class="p">[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.55</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">]],</span>
<span class="gp">... </span>                   <span class="p">[</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="s1">&#39;J&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_g</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.6</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bayesian_model</span><span class="o">.</span><span class="n">add_cpds</span><span class="p">(</span><span class="n">cpd_a</span><span class="p">,</span> <span class="n">cpd_r</span><span class="p">,</span> <span class="n">cpd_j</span><span class="p">,</span> <span class="n">cpd_q</span><span class="p">,</span> <span class="n">cpd_l</span><span class="p">,</span> <span class="n">cpd_g</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">belief_propagation</span> <span class="o">=</span> <span class="n">BeliefPropagation</span><span class="p">(</span><span class="n">bayesian_model</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">belief_propagation</span><span class="o">.</span><span class="n">map_query</span><span class="p">(</span><span class="n">variables</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;J&#39;</span><span class="p">,</span> <span class="s1">&#39;Q&#39;</span><span class="p">],</span>
<span class="gp">... </span>                             <span class="n">evidence</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;A&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;R&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;G&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;L&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">})</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.inference.ExactInference.BeliefPropagation.max_calibrate">
<code class="descname">max_calibrate</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/ExactInference.html#BeliefPropagation.max_calibrate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.ExactInference.BeliefPropagation.max_calibrate" title="Permalink to this definition">¶</a></dt>
<dd><p>Max-calibration of the junction tree using belief propagation.</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">TabularCPD</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.inference</span> <span class="k">import</span> <span class="n">BeliefPropagation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;grade&#39;</span><span class="p">),</span>
<span class="gp">... </span>                   <span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="s1">&#39;SAT&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;grade&#39;</span><span class="p">,</span> <span class="s1">&#39;letter&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diff_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.2</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.8</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">intel_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;intel&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.5</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.3</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.2</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">grade_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;grade&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span>
<span class="gp">... </span>                       <span class="p">[[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">],</span>
<span class="gp">... </span>                        <span class="p">[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">],</span>
<span class="gp">... </span>                        <span class="p">[</span><span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">]],</span>
<span class="gp">... </span>                       <span class="n">evidence</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;diff&#39;</span><span class="p">,</span> <span class="s1">&#39;intel&#39;</span><span class="p">],</span>
<span class="gp">... </span>                       <span class="n">evidence_card</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sat_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;SAT&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span>
<span class="gp">... </span>                     <span class="p">[[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">],</span>
<span class="gp">... </span>                      <span class="p">[</span><span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">]],</span>
<span class="gp">... </span>                     <span class="n">evidence</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;intel&#39;</span><span class="p">],</span> <span class="n">evidence_card</span><span class="o">=</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">letter_cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;letter&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span>
<span class="gp">... </span>                        <span class="p">[[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">],</span>
<span class="gp">... </span>                         <span class="p">[</span><span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">]],</span>
<span class="gp">... </span>                        <span class="n">evidence</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;grade&#39;</span><span class="p">],</span> <span class="n">evidence_card</span><span class="o">=</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">add_cpds</span><span class="p">(</span><span class="n">diff_cpd</span><span class="p">,</span> <span class="n">intel_cpd</span><span class="p">,</span> <span class="n">grade_cpd</span><span class="p">,</span> <span class="n">sat_cpd</span><span class="p">,</span> <span class="n">letter_cpd</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bp</span> <span class="o">=</span> <span class="n">BeliefPropagation</span><span class="p">(</span><span class="n">G</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bp</span><span class="o">.</span><span class="n">max_calibrate</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.inference.ExactInference.BeliefPropagation.query">
<code class="descname">query</code><span class="sig-paren">(</span><em>variables</em>, <em>evidence=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/ExactInference.html#BeliefPropagation.query"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.ExactInference.BeliefPropagation.query" title="Permalink to this definition">¶</a></dt>
<dd><p>Query method using belief propagation.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>variables: list</strong></p>
<blockquote>
<div><p>list of variables for which you want to compute the probability</p>
</div></blockquote>
<p><strong>evidence: dict</strong></p>
<blockquote class="last">
<div><p>a dict key, value pair as {var: state_of_var_observed}
None if no evidence</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">TabularCPD</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.inference</span> <span class="k">import</span> <span class="n">BeliefPropagation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bayesian_model</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;J&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;R&#39;</span><span class="p">,</span> <span class="s1">&#39;J&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;J&#39;</span><span class="p">,</span> <span class="s1">&#39;Q&#39;</span><span class="p">),</span>
<span class="gp">... </span>                                <span class="p">(</span><span class="s1">&#39;J&#39;</span><span class="p">,</span> <span class="s1">&#39;L&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="s1">&#39;L&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_a</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.2</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.8</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_r</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;R&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.4</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.6</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_j</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;J&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span>
<span class="gp">... </span>                   <span class="p">[[</span><span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">],</span>
<span class="gp">... </span>                    <span class="p">[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">]],</span>
<span class="gp">... </span>                   <span class="p">[</span><span class="s1">&#39;R&#39;</span><span class="p">,</span> <span class="s1">&#39;A&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_q</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;Q&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span>
<span class="gp">... </span>                   <span class="p">[[</span><span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">],</span>
<span class="gp">... </span>                    <span class="p">[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">]],</span>
<span class="gp">... </span>                   <span class="p">[</span><span class="s1">&#39;J&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_l</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;L&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span>
<span class="gp">... </span>                   <span class="p">[[</span><span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.45</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">],</span>
<span class="gp">... </span>                    <span class="p">[</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.55</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">]],</span>
<span class="gp">... </span>                   <span class="p">[</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="s1">&#39;J&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_g</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[[</span><span class="mf">0.6</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bayesian_model</span><span class="o">.</span><span class="n">add_cpds</span><span class="p">(</span><span class="n">cpd_a</span><span class="p">,</span> <span class="n">cpd_r</span><span class="p">,</span> <span class="n">cpd_j</span><span class="p">,</span> <span class="n">cpd_q</span><span class="p">,</span> <span class="n">cpd_l</span><span class="p">,</span> <span class="n">cpd_g</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">belief_propagation</span> <span class="o">=</span> <span class="n">BeliefPropagation</span><span class="p">(</span><span class="n">bayesian_model</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">belief_propagation</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">variables</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;J&#39;</span><span class="p">,</span> <span class="s1">&#39;Q&#39;</span><span class="p">],</span>
<span class="gp">... </span>                         <span class="n">evidence</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;A&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;R&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;G&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;L&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">})</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-pgmpy.inference.mplp">
<span id="mplp"></span><h2>MPLP<a class="headerlink" href="#module-pgmpy.inference.mplp" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pgmpy.inference.mplp.Mplp">
<em class="property">class </em><code class="descclassname">pgmpy.inference.mplp.</code><code class="descname">Mplp</code><span class="sig-paren">(</span><em>model</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/mplp.html#Mplp"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.mplp.Mplp" title="Permalink to this definition">¶</a></dt>
<dd><p>Class for performing approximate inference using Max-Product Linear Programming method.</p>
<p>We derive message passing updates that result in monotone decrease of the dual of the
MAP LP Relaxation.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>model: MarkovModel for which inference is to be performed.</strong></p>
<p><strong>Examples</strong></p>
<p><strong>&#8212;&#8212;&#8211;</strong></p>
<p><strong>&gt;&gt;&gt; import numpy as np</strong></p>
<p><strong>&gt;&gt;&gt; from pgmpy.models import MarkovModel</strong></p>
<p><strong>&gt;&gt;&gt; from pgmpy.inference import Mplp</strong></p>
<p><strong>&gt;&gt;&gt; from pgmpy.factors.discrete import DiscreteFactor</strong></p>
<p><strong>&gt;&gt;&gt; student = MarkovModel()</strong></p>
<p><strong>&gt;&gt;&gt; student.add_edges_from([(&#8216;A&#8217;, &#8216;B&#8217;), (&#8216;B&#8217;, &#8216;C&#8217;), (&#8216;C&#8217;, &#8216;D&#8217;), (&#8216;E&#8217;, &#8216;F&#8217;)])</strong></p>
<p><strong>&gt;&gt;&gt; factor_a = DiscreteFactor([&#8216;A&#8217;], cardinality=[2], values=np.array([0.54577, 1.8323]))</strong></p>
<p><strong>&gt;&gt;&gt; factor_b = DiscreteFactor([&#8216;B&#8217;], cardinality=[2], values=np.array([0.93894, 1.065]))</strong></p>
<p><strong>&gt;&gt;&gt; factor_c = DiscreteFactor([&#8216;C&#8217;], cardinality=[2], values=np.array([0.89205, 1.121]))</strong></p>
<p><strong>&gt;&gt;&gt; factor_d = DiscreteFactor([&#8216;D&#8217;], cardinality=[2], values=np.array([0.56292, 1.7765]))</strong></p>
<p><strong>&gt;&gt;&gt; factor_e = DiscreteFactor([&#8216;E&#8217;], cardinality=[2], values=np.array([0.47117, 2.1224]))</strong></p>
<p><strong>&gt;&gt;&gt; factor_f = DiscreteFactor([&#8216;F&#8217;], cardinality=[2], values=np.array([1.5093, 0.66257]))</strong></p>
<p><strong>&gt;&gt;&gt; factor_a_b = DiscreteFactor([&#8216;A&#8217;, &#8216;B&#8217;], cardinality=[2, 2],</strong></p>
<p><strong>...                             values=np.array([1.3207, 0.75717, 0.75717, 1.3207]))</strong></p>
<p><strong>&gt;&gt;&gt; factor_b_c = DiscreteFactor([&#8216;B&#8217;, &#8216;C&#8217;], cardinality=[2, 2],</strong></p>
<p><strong>...                             values=np.array([0.00024189, 4134.2, 4134.2, 0.00024189]))</strong></p>
<p><strong>&gt;&gt;&gt; factor_c_d = DiscreteFactor([&#8216;C&#8217;, &#8216;D&#8217;], cardinality=[2, 2],</strong></p>
<p><strong>...                             values=np.array([0.0043227, 231.34, 231.34, 0.0043227]))</strong></p>
<p><strong>&gt;&gt;&gt; factor_d_e = DiscreteFactor([&#8216;E&#8217;, &#8216;F&#8217;], cardinality=[2, 2],</strong></p>
<p><strong>...                             values=np.array([31.228, 0.032023, 0.032023, 31.228]))</strong></p>
<p><strong>&gt;&gt;&gt; student.add_factors(factor_a, factor_b, factor_c, factor_d, factor_e, factor_f, factor_a_b,</strong></p>
<p><strong>...                     factor_b_c, factor_c_d, factor_d_e)</strong></p>
<p class="last"><strong>&gt;&gt;&gt; mplp = Mplp(student)</strong></p>
</td>
</tr>
</tbody>
</table>
<dl class="class">
<dt id="pgmpy.inference.mplp.Mplp.Cluster">
<em class="property">class </em><code class="descname">Cluster</code><span class="sig-paren">(</span><em>intersection_set_variables</em>, <em>cluster_potential</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/mplp.html#Mplp.Cluster"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.mplp.Mplp.Cluster" title="Permalink to this definition">¶</a></dt>
<dd><p>Inner class for representing a cluster.
A cluster is a subset of variables.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>set_of_variables: tuple</strong></p>
<blockquote>
<div><p>This is the set of variables that form the cluster.</p>
</div></blockquote>
<p><strong>intersection_set_variables: set containing frozensets.</strong></p>
<blockquote>
<div><blockquote>
<div><p>collection of intersection of all pairs of cluster variables.</p>
</div></blockquote>
<p>For eg: {{C_1 cap C_2}, {C_2 cap C_3}, {C_3 cap C_1} } for clusters C_1, C_2 &amp; C_3.</p>
</div></blockquote>
<p><strong>cluster_potential: DiscreteFactor</strong></p>
<blockquote class="last">
<div><p>Each cluster has a initial probability distribution provided beforehand.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="pgmpy.inference.mplp.Mplp.find_triangles">
<code class="descclassname">Mplp.</code><code class="descname">find_triangles</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/mplp.html#Mplp.find_triangles"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.mplp.Mplp.find_triangles" title="Permalink to this definition">¶</a></dt>
<dd><p>Finds all the triangles present in the given model</p>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">MarkovModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.inference</span> <span class="k">import</span> <span class="n">Mplp</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span> <span class="o">=</span> <span class="n">MarkovModel</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">([</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x3&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x5&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x3&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x4&#39;</span><span class="p">),</span>
<span class="gp">... </span>                   <span class="p">(</span><span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="s1">&#39;x5&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x3&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x6&#39;</span><span class="p">),</span>
<span class="gp">... </span>                   <span class="p">(</span><span class="s1">&#39;x4&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;x5&#39;</span><span class="p">,</span> <span class="s1">&#39;x7&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phi</span> <span class="o">=</span> <span class="p">[</span><span class="n">DiscreteFactor</span><span class="p">(</span><span class="n">edge</span><span class="p">,</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">))</span> <span class="k">for</span> <span class="n">edge</span> <span class="ow">in</span> <span class="n">mm</span><span class="o">.</span><span class="n">edges</span><span class="p">()]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mm</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="o">*</span><span class="n">phi</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mplp</span> <span class="o">=</span> <span class="n">Mplp</span><span class="p">(</span><span class="n">mm</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mplp</span><span class="o">.</span><span class="n">find_triangles</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="pgmpy.inference.mplp.Mplp.get_integrality_gap">
<code class="descclassname">Mplp.</code><code class="descname">get_integrality_gap</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/mplp.html#Mplp.get_integrality_gap"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.mplp.Mplp.get_integrality_gap" title="Permalink to this definition">¶</a></dt>
<dd><dl class="docutils">
<dt>Returns the integrality gap of the current state of the Mplp algorithm. The lesser it is, the closer we are</dt>
<dd>towards the exact solution.</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="pgmpy.inference.mplp.Mplp.map_query">
<code class="descclassname">Mplp.</code><code class="descname">map_query</code><span class="sig-paren">(</span><em>init_iter=1000</em>, <em>later_iter=20</em>, <em>dual_threshold=0.0002</em>, <em>integrality_gap_threshold=0.0002</em>, <em>tighten_triplet=True</em>, <em>max_triplets=5</em>, <em>max_iterations=100</em>, <em>prolong=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/mplp.html#Mplp.map_query"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.mplp.Mplp.map_query" title="Permalink to this definition">¶</a></dt>
<dd><p>MAP query method using Max Product LP method.
This returns the best assignment of the nodes in the form of a dictionary.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>init_iter: integer</strong></p>
<blockquote>
<div><p>Number of maximum iterations that we want MPLP to run for the first time.</p>
</div></blockquote>
<p><strong>later_iter: integer</strong></p>
<blockquote>
<div><p>Number of maximum iterations that we want MPLP to run for later iterations</p>
</div></blockquote>
<p><strong>dual_threshold: double</strong></p>
<blockquote>
<div><p>This sets the minimum width between the dual objective decrements. If the decrement is lesser
than the threshold, then that means we have stuck on a local minima.</p>
</div></blockquote>
<p><strong>integrality_gap_threshold: double</strong></p>
<blockquote>
<div><p>This sets the threshold for the integrality gap below which we say that the solution
is satisfactory.</p>
</div></blockquote>
<p><strong>tighten_triplet: bool</strong></p>
<blockquote>
<div><p>set whether to use triplets as clusters or not.</p>
</div></blockquote>
<p><strong>max_triplets: integer</strong></p>
<blockquote>
<div><p>Set the maximum number of triplets that can be added at once.</p>
</div></blockquote>
<p><strong>max_iterations: integer</strong></p>
<blockquote>
<div><p>Maximum number of times we tighten the relaxation. Used only when tighten_triplet is set True.</p>
</div></blockquote>
<p><strong>prolong: bool</strong></p>
<blockquote>
<div><p>If set False: The moment we exhaust of all the triplets the tightening stops.
If set True: The tightening will be performed max_iterations number of times irrespective of the</p>
<blockquote>
<div><p>triplets.</p>
</div></blockquote>
</div></blockquote>
<p><strong>Reference:</strong></p>
<p><strong>Section 3.3: The Dual Algorithm; Tightening LP Relaxation for MAP using Message Passing (2008)</strong></p>
<p class="last"><strong>By Sontag Et al.</strong></p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">MarkovModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.inference</span> <span class="k">import</span> <span class="n">Mplp</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span> <span class="o">=</span> <span class="n">MarkovModel</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">([(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;E&#39;</span><span class="p">,</span> <span class="s1">&#39;F&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor_a</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;A&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">values</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.54577</span><span class="p">,</span> <span class="mf">1.8323</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor_b</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;B&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">values</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.93894</span><span class="p">,</span> <span class="mf">1.065</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor_c</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;C&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">values</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.89205</span><span class="p">,</span> <span class="mf">1.121</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor_d</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;D&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">values</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.56292</span><span class="p">,</span> <span class="mf">1.7765</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor_e</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;E&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">values</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.47117</span><span class="p">,</span> <span class="mf">2.1224</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor_f</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;F&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">values</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">1.5093</span><span class="p">,</span> <span class="mf">0.66257</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor_a_b</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span>
<span class="gp">... </span>                            <span class="n">values</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">1.3207</span><span class="p">,</span> <span class="mf">0.75717</span><span class="p">,</span> <span class="mf">0.75717</span><span class="p">,</span> <span class="mf">1.3207</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor_b_c</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span>
<span class="gp">... </span>                            <span class="n">values</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.00024189</span><span class="p">,</span> <span class="mf">4134.2</span><span class="p">,</span> <span class="mf">4134.2</span><span class="p">,</span> <span class="mf">0.0002418</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor_c_d</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span>
<span class="gp">... </span>                            <span class="n">values</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.0043227</span><span class="p">,</span> <span class="mf">231.34</span><span class="p">,</span> <span class="mf">231.34</span><span class="p">,</span> <span class="mf">0.0043227</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor_d_e</span> <span class="o">=</span> <span class="n">DiscreteFactor</span><span class="p">([</span><span class="s1">&#39;E&#39;</span><span class="p">,</span> <span class="s1">&#39;F&#39;</span><span class="p">],</span> <span class="n">cardinality</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span>
<span class="gp">... </span>                            <span class="n">values</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">31.228</span><span class="p">,</span> <span class="mf">0.032023</span><span class="p">,</span> <span class="mf">0.032023</span><span class="p">,</span> <span class="mf">31.228</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">student</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">factor_a</span><span class="p">,</span> <span class="n">factor_b</span><span class="p">,</span> <span class="n">factor_c</span><span class="p">,</span> <span class="n">factor_d</span><span class="p">,</span> <span class="n">factor_e</span><span class="p">,</span> <span class="n">factor_f</span><span class="p">,</span>
<span class="gp">... </span>                    <span class="n">factor_a_b</span><span class="p">,</span> <span class="n">factor_b_c</span><span class="p">,</span> <span class="n">factor_c_d</span><span class="p">,</span> <span class="n">factor_d_e</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mplp</span> <span class="o">=</span> <span class="n">Mplp</span><span class="p">(</span><span class="n">student</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">result</span> <span class="o">=</span> <span class="n">mplp</span><span class="o">.</span><span class="n">map_query</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">result</span>
<span class="go">{&#39;B&#39;: 0.93894, &#39;C&#39;: 1.121, &#39;A&#39;: 1.8323, &#39;F&#39;: 1.5093, &#39;D&#39;: 1.7765, &#39;E&#39;: 2.12239}</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-pgmpy.inference.dbn_inference">
<span id="dynamic-bayesian-network-inference"></span><h2>Dynamic Bayesian Network Inference<a class="headerlink" href="#module-pgmpy.inference.dbn_inference" title="Permalink to this headline">¶</a></h2>
</div>
</div>
<div class="section" id="module-pgmpy.inference.EliminationOrder">
<span id="elimination-ordering"></span><h1>Elimination Ordering<a class="headerlink" href="#module-pgmpy.inference.EliminationOrder" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="pgmpy.inference.EliminationOrder.BaseEliminationOrder">
<em class="property">class </em><code class="descclassname">pgmpy.inference.EliminationOrder.</code><code class="descname">BaseEliminationOrder</code><span class="sig-paren">(</span><em>model</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/EliminationOrder.html#BaseEliminationOrder"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.EliminationOrder.BaseEliminationOrder" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for finding elimination orders.</p>
<dl class="method">
<dt id="pgmpy.inference.EliminationOrder.BaseEliminationOrder.cost">
<code class="descname">cost</code><span class="sig-paren">(</span><em>node</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/EliminationOrder.html#BaseEliminationOrder.cost"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.EliminationOrder.BaseEliminationOrder.cost" title="Permalink to this definition">¶</a></dt>
<dd><p>The cost function to compute the cost of elimination of each node.
This method is just a dummy and returns 0 for all the nodes. Actual cost functions
are implemented in the classes inheriting BaseEliminationOrder.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>node: string, any hashable python object.</strong></p>
<blockquote class="last">
<div><p>The node whose cost is to be computed.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="pgmpy.inference.EliminationOrder.BaseEliminationOrder.fill_in_edges">
<code class="descname">fill_in_edges</code><span class="sig-paren">(</span><em>node</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/EliminationOrder.html#BaseEliminationOrder.fill_in_edges"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.EliminationOrder.BaseEliminationOrder.fill_in_edges" title="Permalink to this definition">¶</a></dt>
<dd><p>Return edges needed to be added to the graph if a node is removed.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>node: string (any hashable python object)</strong></p>
<blockquote class="last">
<div><p>Node to be removed from the graph.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="pgmpy.inference.EliminationOrder.BaseEliminationOrder.get_elimination_order">
<code class="descname">get_elimination_order</code><span class="sig-paren">(</span><em>nodes=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pgmpy/inference/EliminationOrder.html#BaseEliminationOrder.get_elimination_order"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pgmpy.inference.EliminationOrder.BaseEliminationOrder.get_elimination_order" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the optimal elimination order based on the cost function.
The node having the least cost is removed first.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>nodes: list, tuple, set (array-like)</strong></p>
<blockquote class="last">
<div><p>The variables which are to be eliminated.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">TabularCPD</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pgmpy.inference.EliminationOrder</span> <span class="k">import</span> <span class="n">WeightedMinFill</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">([(</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="s1">&#39;d&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;d&#39;</span><span class="p">,</span> <span class="s1">&#39;g&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;i&#39;</span><span class="p">,</span> <span class="s1">&#39;g&#39;</span><span class="p">),</span>
<span class="gp">... </span>                       <span class="p">(</span><span class="s1">&#39;i&#39;</span><span class="p">,</span> <span class="s1">&#39;s&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;s&#39;</span><span class="p">,</span> <span class="s1">&#39;j&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;g&#39;</span><span class="p">,</span> <span class="s1">&#39;l&#39;</span><span class="p">),</span>
<span class="gp">... </span>                       <span class="p">(</span><span class="s1">&#39;l&#39;</span><span class="p">,</span> <span class="s1">&#39;j&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;j&#39;</span><span class="p">,</span> <span class="s1">&#39;h&#39;</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;g&#39;</span><span class="p">,</span> <span class="s1">&#39;h&#39;</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_c</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_d</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;d&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">[</span><span class="s1">&#39;c&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_g</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;g&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">[</span><span class="s1">&#39;d&#39;</span><span class="p">,</span> <span class="s1">&#39;i&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_i</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;i&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_s</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;s&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">[</span><span class="s1">&#39;i&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_j</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;j&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">[</span><span class="s1">&#39;l&#39;</span><span class="p">,</span> <span class="s1">&#39;s&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_l</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;l&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">[</span><span class="s1">&#39;g&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cpd_h</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="s1">&#39;h&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">6</span><span class="p">),</span>
<span class="gp">... </span>                  <span class="p">[</span><span class="s1">&#39;g&#39;</span><span class="p">,</span> <span class="s1">&#39;j&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span><span class="o">.</span><span class="n">add_cpds</span><span class="p">(</span><span class="n">cpd_c</span><span class="p">,</span> <span class="n">cpd_d</span><span class="p">,</span> <span class="n">cpd_g</span><span class="p">,</span> <span class="n">cpd_i</span><span class="p">,</span> <span class="n">cpd_s</span><span class="p">,</span> <span class="n">cpd_j</span><span class="p">,</span>
<span class="gp">... </span>               <span class="n">cpd_l</span><span class="p">,</span> <span class="n">cpd_h</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">WeightedMinFill</span><span class="p">(</span><span class="n">model</span><span class="p">)</span><span class="o">.</span><span class="n">get_elimination_order</span><span class="p">([</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="s1">&#39;d&#39;</span><span class="p">,</span> <span class="s1">&#39;g&#39;</span><span class="p">,</span> <span class="s1">&#39;l&#39;</span><span class="p">,</span> <span class="s1">&#39;s&#39;</span><span class="p">])</span>
<span class="go">[&#39;c&#39;, &#39;s&#39;, &#39;l&#39;, &#39;d&#39;, &#39;g&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">WeightedMinFill</span><span class="p">(</span><span class="n">model</span><span class="p">)</span><span class="o">.</span><span class="n">get_elimination_order</span><span class="p">([</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="s1">&#39;d&#39;</span><span class="p">,</span> <span class="s1">&#39;g&#39;</span><span class="p">,</span> <span class="s1">&#39;l&#39;</span><span class="p">,</span> <span class="s1">&#39;s&#39;</span><span class="p">])</span>
<span class="go">[&#39;c&#39;, &#39;s&#39;, &#39;l&#39;, &#39;d&#39;, &#39;g&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">WeightedMinFill</span><span class="p">(</span><span class="n">model</span><span class="p">)</span><span class="o">.</span><span class="n">get_elimination_order</span><span class="p">([</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="s1">&#39;d&#39;</span><span class="p">,</span> <span class="s1">&#39;g&#39;</span><span class="p">,</span> <span class="s1">&#39;l&#39;</span><span class="p">,</span> <span class="s1">&#39;s&#39;</span><span class="p">])</span>
<span class="go">[&#39;c&#39;, &#39;s&#39;, &#39;l&#39;, &#39;d&#39;, &#39;g&#39;]</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="readwrite.html" title="Reading and Writing from files"
             >next</a> |</li>
        <li class="right" >
          <a href="sampling.html" title="Sampling Methods"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">pgmpy 0.1.2 documentation</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2016, Ankur Ankan.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.1.
    </div>
  </body>
</html>